package com.emar.adx.yiqifa.util;

public class ApplicationUtil {

	public static String getRootPath() {
		String result = ApplicationUtil.class.getResource("ApplicationUtil.class").toString();
		if(result != null) {
			result = result.replaceAll("%20", " ");
		}
		int index = result.indexOf("WEB-INF");
		if (index == -1) {
			index = result.indexOf("bin");
		}
		result = result.substring(0, index);
		if (result.startsWith("jar")) {
			result = result.substring(10);
		} else if (result.startsWith("file")) {
			result = result.substring(6);
		}
		if (result.endsWith("/"))
			result = result.substring(0, result.length() - 1);
		return result;
	}

	/**
	 *
	 * @param path
	 * @return
	 */
	public static String getRealPath(String path) {
		if(path.startsWith("/")){
			return getRootPath() + path;
		}
		return "/" + getRootPath() + path;
	}

    public void test(){

    }

}
